<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>盒模型</title>
    <style>
        /* 默认的和模型，元素的实际宽度=边框宽度+内边距+width */
        #d1{
            width: 300px;
            height: 300px;
            border:2px solid blue;
            padding:20px 20px;
        }

        #d2{
            width: 250px;
            height: 250px;
            background-color: red;
        }

        #d3{
            width: 300px;
            height: 300px;
            border:2px solid blue;
            padding:20px 20px;
            /* 对盒模型进行设置，元素实际的宽度=width */
            box-sizing: border-box;
        }

        #d4{
            width: 250px;
            height: 250px;
            background-color: red;
        }
    </style>
</head>
<body>
    <div id="d1">
        <div id="d2"></div> 
    </div>

    <div id="d3">
        <div id="d4"></div> 
    </div>
</body>
</html>